package com.mjlf.mr.data;

import org.apache.commons.lang3.RandomUtils;
import org.junit.Test;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName: CreateData
 * @Author: majun
 * @CreateDate: 2018/12/18 10:20
 * @Version: 1.0
 * @Description: TODO
 */

public class CreateData {
//    @Test
//    public void test() throws IOException {
//        String[] names = {"java", "hadoop", "javascript", "css", "python", "c", "c++", "phh", "c#", "go", "html", "hive",
//                "hbase"};
//
//        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("names.txt")));
//        for (int i = 0; i < 10000000; i++) {
//            StringBuilder stringBuilder = new StringBuilder();
//            int nums = RandomUtils.nextInt(5, 10);
//            for (int j = 0; j < nums; j++) {
//                String name = names[RandomUtils.nextInt(0, names.length)];
//                if (j == 0) {
//                    stringBuilder.append(name);
//                } else {
//                    stringBuilder.append(" " + name);
//                }
//            }
//            writer.write(stringBuilder.toString() + "\n");
//        }
//        writer.close();
//    }

    public String testRandomTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.SECOND, -RandomUtils.nextInt(0, 1000000000));
        return  sdf.format(calendar.getTime());
    }

    @Test
    public void createSpeed() throws IOException {
        String[] carNum = new String[]{"A-00AX", "A-00AC", "A-00BX", "A-00BC", "A-00CX", "A-00CC", "A-00DX",
                "A-00DC", "A-00EX", "A-00EC", "A-00EX", "A-00EC", "A-00FX", "A-00FC", "A-00GX", "A-00GC",
                "A-00HX", "A-00HC", "A-00IX", "A-00IC", "A-00JX", "A-00JC", "A-00KX", "A-00KC", "A-00LX", "A-00LC",
                "A-00MX", "A-00MC", "A-00NX", "A-00NC", "A-00OX", "A-00OC", "A-00PX", "A-00PC", "A-00QX", "A-00QC", };
        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("speed.txt")));
        for(int i = 0; i < 10000; i ++){
            String time = testRandomTime();
            String carN = carNum[RandomUtils.nextInt(0, carNum.length)];
            double speed = RandomUtils.nextDouble(0, 200.0);
            writer.write(time + "\t" + carN + "\t" + speed + "\n");
        }
        writer.close();
    }
}
